package com.bear.atlassianmcp.confluence.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

/**
 * Confluence空间数据模型
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConfluenceSpace {

    private Integer id;
    private String key;
    private String name;
    private String type;
    private String status;
    
    @JsonProperty("_links")
    private Map<String, Object> links;
    
    private ConfluenceSpaceDescription description;
    private Map<String, Object> metadata;

    /**
     * 获取空间的Web URL
     */
    public String getWebUrl() {
        if (links != null && links.containsKey("webui")) {
            return (String) links.get("webui");
        }
        return null;
    }

    /**
     * 获取空间描述文本
     */
    public String getDescriptionText() {
        if (description != null && description.getPlain() != null) {
            return description.getPlain().getValue();
        }
        return null;
    }

    /**
     * 格式化为AI友好的文本描述
     */
    public String toFormattedString() {
        StringBuilder sb = new StringBuilder();
        sb.append("🏠 空间: ").append(name).append("\n");
        sb.append("🔑 键值: ").append(key).append("\n");
        sb.append("🆔 ID: ").append(id).append("\n");
        sb.append("📊 状态: ").append(status).append("\n");
        sb.append("📂 类型: ").append(type).append("\n");
        
        String desc = getDescriptionText();
        if (desc != null && !desc.trim().isEmpty()) {
            String preview = desc.length() > 150 ? desc.substring(0, 150) + "..." : desc;
            sb.append("📝 描述: ").append(preview).append("\n");
        }
        
        String webUrl = getWebUrl();
        if (webUrl != null) {
            sb.append("🔗 链接: ").append(webUrl).append("\n");
        }
        
        return sb.toString();
    }

    // Getters and Setters
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Map<String, Object> getLinks() {
        return links;
    }

    public void setLinks(Map<String, Object> links) {
        this.links = links;
    }

    public ConfluenceSpaceDescription getDescription() {
        return description;
    }

    public void setDescription(ConfluenceSpaceDescription description) {
        this.description = description;
    }

    public Map<String, Object> getMetadata() {
        return metadata;
    }

    public void setMetadata(Map<String, Object> metadata) {
        this.metadata = metadata;
    }
}
